<?php
session_start();
include "config/identitas-situs.php";
include "config/koneksi.php";
include "config/tanggalan.php";
include "config/library.php";

?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>
Pendaftaran Calon Siswa Baru &laquo; <?php echo $title; ?>
</title>

<link rel="shortcut icon" href="images/icon.ico" />
<link href="config/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<style>
input.error, textarea.error, select.error {
	background-color:#FFFFCC !important;
	border:1px solid #CC0000 !important;
}
label.error {
	color:#CC0000 !important;
	font-family:Arial, Helvetica, sans-serif !important;
	font-size:11px !important;
	padding-left:5px !important;
}
</style>
</head>
<body>
 <div id="lebar-web">
	<div id="header">
		<div class="header-judul"><?php echo $namasitus; ?></div>
		<div class="header-deskripsi"><?php echo $deskripsi; ?></div>
	</div>
	<ul id="menu_nav" class="Blue">
		<li class="button"><a href="index.php">Beranda</a></li>
		<li class="button"><a href="berita.php">Informasi PPDB</a></li>
		<li class="button"><a href="profil.php">Profil Sekolah</a></li>
		<li class="button"><a href="daftar.php">Pendaftaran</a></li>
        <li class="button"><a href="jurusan.php">Program Keahlian</a></li>
		
        <li class="button"><a href="login.php">Masuk</a></li>		
	 </ul>
  <div id="isi">

<H1>Formulir Pendaftaran Calon Siswa Baru SMK Negeri 1 Kebumen</H1>


<?php
include "config/koneksi.php";
$aksi=$_GET['aksi'];

//AKSI DAFTAR atau REGISTRASI
if($aksi=="registrasi")
{

	$no_pendaftaran=$_POST[no_pendaftaran];
	$tgl_daftar=$_POST[tgl_daftar];
	$proli=$_POST[proli];
	$nama=$_POST[nama];
	$jk=$_POST[jk];
	$tmpt_lahir=$_POST[tmpt_lahir];
	$tgl_lahir=$_POST[thn]."-".$_POST[bulan]."-".$_POST[tgl];
	$agama=$_POST[agama];
	$nama_ortu=$_POST[nama_ortu];
	$pekerjaan_ortu=$_POST[pekerjaan_ortu];
	$alamat=$_POST[alamat];
	$no_hp=$_POST[no_hp];
	$asal_sekolah=$_POST[asal_sekolah];
	$matematika=$_POST[matematika];
	$indonesia=$_POST[indonesia];
	$inggris=$_POST[inggris];
	$ipa=$_POST[ipa];
	$ket_ijazah=$_POST[ket_ijazah];
   	$user_id=$_POST[user_id];

	
	$phari=array();
	if(checkdate($_POST['bulan'], $_POST['tgl'], $_POST['thn'])) //untuk memvalidasi tanggal lahir
	{
		$currentDate= date('Y-m-d');
		$yesterday = strtotime ( '-0 day', strtotime ($currentDate));
		$inputDate = $_POST['thn']."-".$_POST['bulan']."-".$_POST['tgl'];
		$inputDate = strtotime($inputDate);
		if($inputDate <= $yesterday)
		{
			$val_tgl='1';
		}
	}

	if(isset($_POST['hari1']) || isset($_POST['hari2']) || isset($_POST['hari3']) || isset($_POST['hari4']) || isset($_POST['hari5']) || isset($_POST['hari6']))
	{
		$pilih = array();
		if(isset($_POST['hari1']))
		{
			$phari[]="senin";
			$pilih[]=$_POST['hari1'];
			$outhari.="Senin, ";
		}
		if(isset($_POST['hari2']))
		{
			$phari[]="selasa";
			$pilih[]=$_POST['hari2'];
			$outhari.="Selasa, ";
		}
		if(isset($_POST['hari3']))
		{
			$phari[]="rabu";
			$pilih[]=$_POST['hari3'];
			$outhari.="Rabu, ";
		}
		if(isset($_POST['hari4']))
		{	
			$phari[]="kamis";
			$pilih[]=$_POST['hari4'];
			$outhari.="Kamis, ";
		}
		if(isset($_POST['hari5']))
		{	
			$phari[]="jumat";
			$pilih[]=$_POST['hari5'];
			$outhari.="Jumat, ";
		}
		if(isset($_POST['hari6']))
		{
			$phari[]="sabtu";
			$pilih[]=$_POST['hari6'];
			$outhari.="Sabtu, ";
		}
		$pilihhari=json_encode($phari);

		$hari= array(0,1,2,3,4,5,6);
		$days = date('w');
		$ini = $hari[$days];
		$tambah = 0;
		$b=$ini;
		$w=0;
		

		for ($i=0; $i<=count($pilih); $i++)
		{	
			$jadi.=$pilih[$i].", ";
		}

		while($w < 1)
		{
			$tambah++;
			$b++;
			if($b==8)$b=1;
			if($b==$pilih[0])$w=1;
		}

		function tanggal($ke)
		{
			$akan = mktime(0, 0, 0, date('m'), date('d') + $ke, date('y'));
			return date("Y-m-d", $akan);
		}

		$pertm=count($pilih);
		$total=ceil($jpert/count($pilih));

		$tgl_daftar=date("Y-m-d");
	}
	
	
	
	
		if($_POST['kode']==$_SESSION['captcha_session'])
		{
			
					$kueri_daftar=mysql_query("INSERT INTO tb_pendaftar(no_pendaftaran,tgl_daftar,proli,nama,jk,tmpt_lahir,tgl_lahir,agama,
					nama_ortu,pekerjaan_ortu,alamat,no_hp,asal_sekolah,matematika,indonesia,inggris,ipa,ket_ijazah,user_id)
					VALUES('$no_pendaftaran','$tgl_daftar','$proli','$nama','$jk','$_POST[tmpt_lahir]','$tgl_lahir','$agama','$nama_ortu',
					'$pekerjaan_ortu','$alamat','$no_hp','$asal_sekolah','$matematika','$indonesia','$inggris','$ipa','$ket_ijazah','$user_id')");
					
	  
					if($kueri_daftar)
					{
						$ambil_id=mysql_fetch_array(mysql_query("SELECT * FROM tb_pendaftar ORDER BY no_pendaftaran DESC LIMIT 1"));
						$id=$ambil_id['no_pendaftaran'];
						$agama=mysql_fetch_array(mysql_query("SELECT * FROM tb_agama WHERE id_agama= '$agama'"));
						$proli=mysql_fetch_array(mysql_query("SELECT * FROM tb_proli WHERE kd_proli= '$proli'"));
						if($jk=="1")
						{
							$kelamin ="Laki-Laki";
						}else
						{
							$kelamin="Perempuan";
						}
						?>
						<center><b><img src="images/hepi.gif" /><br />Pendaftaran Berhasil<br />Terima kasih. Data Anda sudah kami terima.</b></center><br /><br />
						<table id="belang">
						<tr>
							<th>No.Pendaftaran Anda adalah</th>
							<td><?php echo $ambil_id['no_pendaftaran']; ?></td>
						</tr>
						<tr>
							<th>Tanggal daftar</th>
							<td><?php echo $tgl_daftar['tgl_daftar']; ?></td>
						</tr>
						<tr>
							<th>Program Keahlian</th>
							<td><?php echo $proli['proli']; ?></td>
						</tr>
						<tr>
							<th>Nama</th>
							<td><?php echo $ambil_id['nama']; ?></td>
						</tr>
						<tr>
							<th>Jenis Kelamin</th>
							<td><?php echo $kelamin; ?></td>
							</tr>
                        <tr>
							<th>Tempat, Tgl Lahir</th>
							<td><?php echo "$_POST[tmpt_lahir], ".tanggalan($ambil_id['tgl_lahir']); ?></td>
						</tr>
                        <tr>
							<th>Agama</th>
							<td><?php echo $agama['agama']; ?></td>
						</tr>
                        <tr>
							<th valign="middle">Nama Orang Tua</th>
							<td><?php echo $ambil_id['nama_ortu']; ?></td>
						</tr>
						<tr>
							<th valign="middle">Pekerjaan Orang Tua</th>
							<td><?php echo $ambil_id['pekerjaan_ortu']; ?></td>
						</tr>
						<tr>
							<th valign="middle">Alamat</th>
							<td><?php echo $ambil_id['alamat']; ?></td>
						</tr>
						<tr>
							<th valign="middle">No Handphone</th>
							<td><?php echo $ambil_id['no_hp'];?></td>
						</tr>
						<tr>
							<th valign="middle">Asal Sekolah</th>
							<td><?php echo $ambil_id['asal_sekolah']; ?></td>
						</tr>
						<tr>
							<th valign="middle">Nilai Matematika</th>
							<td><?php echo $ambil_id['matematika']; ?></td>
						</tr>
						<tr>
							<th valign="middle">Nilai Bhs.Indonesia</th>
							<td><?php echo $ambil_id['indonesia']; ?></td>
						</tr>
						<tr>
							<th valign="middle">Nilai Bhs.Inggris</th>
							<td><?php echo $ambil_id['inggris']; ?></td>
						</tr>
						<tr>
							<th valign="middle">Nilai IPA</th>
							<td><?php echo $ambil_id['ipa']; ?></td>
						</tr>
                        <tr>
							<th valign="middle">Keterangan Ijazah</th>
							<td><?php echo $ambil_id['ket_ijazah']; ?></td>
						</tr>
						 
										
					</table>
					
					
					<?php
					}
					
					else 
					{ 
						echo "<center><font color='RED'><img src='images/sad.gif' /><br>Pendaftaran Gagal, lengkapi data dengan benar</font><br><a href='javascript:history.go(-1)'>Ulangi</a></center>";
					}
				
		}
		else
		{
			echo "<center><font color='RED'><img src='images/sad.gif' /><br>Kode Aman Salah!</font><br><a href='javascript:history.go(-1)'>Ulangi</a></center>";
		}
	
	
}

// HASIL PENCARIAN PESERTA TERDAFTAR
elseif($aksi=="hasil-cari"){
$kata=$_POST[kata_kunci];
if(!empty($kata)){
$cari=mysql_query("SELECT * FROM tb_pendaftar WHERE nama LIKE '%$kata%'");	
$ketemu=mysql_num_rows($cari);
 if($ketemu > 0){
 	echo "Ditemukan <b>$ketemu</b> data siswa terdaftar dengan nama <font style='background-color:#FEEA36'><b>$kata</b></font> :<br><br>";
	while($c=mysql_fetch_array($cari)){
	$agama=mysql_fetch_array(mysql_query("SELECT * FROM tb_agama WHERE id_agama= '$c[id_agama]'"));
	$proli=mysql_fetch_array(mysql_query("SELECT * FROM tb_proli WHERE kd_proli= '$c[proli]'"));
	if($c[jk]=="1"){
	$jk ="Laki-Laki";
	}else{
	$jk="Perempuan";}
?> 
<fieldset style="border:1px solid #0099FF;">
<legend style="font-weight:bold; color:#0066CC">
Data Lengkap untuk <?php echo $c[nama]; ?>
</legend>
<table id="belang">
<tr>
  	<th>Pilih Proli</th>
  	<td><?php echo $proli[proli]; ?></td>
  </tr>
  <tr>
  	<th width="31%">Nama</th>
	<td width="69%"><?php echo $c[nama]; ?></td>
  </tr>
  
  <tr>
  	<th>Jenis Kelamin</th>
	<td><?php echo $jk; ?></td>
  </tr>
  <tr>
  	<th>Tempat, Tgl Lahir</th>
  	<td><?php echo "$c[tmpt_lahir], $c[tgl_lahir]"; ?></td>
  </tr> 
  <tr>
  	<th>Agama</th>
  	<td><?php echo $agama[agama]; ?></td>
  </tr>
   <tr>
   	<th valign="middle">Asal Sekolah</th>
	<td><?php echo $c[asal_sekolah]; ?></td>
  </tr>
 
  <tr>
   	<th valign="middle">Alamat</th>
	<td><?php echo $c[alamat]; ?></td>
  </tr>
 <tr>
    <th>No Handphone</th>
	<td><?php echo $c[no_hp]; ?></td>
  </tr>
  <tr>
   	<th valign="middle">Nilai Matematika</th>
	<td><?php echo $c[matematika]; ?></td>
  </tr>
  <tr>
   	<th valign="middle">Nilai Bhs.Indonesia</th>
	<td><?php echo $c[indonesia]; ?></td>
  </tr>
  
  <tr>
   	<th valign="middle">Nilai Bhs.Inggris</th>
	<td><?php echo $c[inggris]; ?></td>
	 <tr>
   	<th valign="middle">Nilai IPA</th>
	<td><?php echo $c[ipa]; ?></td>
  </tr> 
 
</table>
</fieldset>
 <p>
   <?php
	}
echo "<font color='RED'>Jika ada data yang tidak tepat dan ingin diperbaiki, silakan Hubungi Kami atau Daftar lagi.</font>";
 } else { echo "<center>Tidak ditemukan data siswa terdaftar dengan nama <i>'$kata'</i>.<br><a href='javascript:history.back()'>Kembali</a></center>"; }
} else { echo "<center>Isi nama Anda di kolom pencarian!<br><a href='javascript:history.back()'>Ulangi</a></center>"; }

}  else { 


// KOTAK PENCARIAN dan FORMULIR PENDAFTARAN
?>
 </p>
 <fieldset style="border:1px solid #0099FF; background:#CCFFFF">
<legend style="font-weight:bold; color:#0066CC">silahkan isi data anda dengan lengkap
 </legend>
</fieldset>
<br />
<form name="formdaftar" action="daftar.php?aksi=registrasi" method="post" id="form_daftar">
<form action="aksi/registrasi.php" method="POST">
<table id="belang">
  <tr>
  	<th>No.Pendaftaran</th>
	<td><input type="text" name="no_pendaftaran" size="5" class="required" /></td>
  </tr>
  <tr>
  	<th>Tanggal Daftar</th>
	<td><input type="text" name="tgl_daftar" size="15" value="<?php echo date('d M Y');?>" class="required" readonly/>
  </tr>
  <tr>
  <th>Program Keahlian yang dipilih</th>
	<td>
	<select name="proli" class="required">	
	<option value="">--Pilih Proli--</option>
    <?php
      // tampilkan proli
      $sql1 = mysql_query("SELECT * FROM tb_proli");
      while($k=mysql_fetch_array($sql1)){
         echo "<option value=$k[proli]>$k[proli]</option> \n";
      }
     ?>
      </select>
	</td>
	</tr>
  <tr>
  	<th>Nama</th>
	<td><input type="text" name="nama" size="50" class="required" /></td>
  </tr>
   <tr>
<th>Jenis Kelamin</th>
  <td>
<input type="radio" name="jk" value="1" checked="checked">Laki-laki
<input type="radio" name="jk" value="2">Perempuan
  </td>
  </tr>   	
  <tr>
  <th>Tempat, Tgl Lahir</th>
	
  	<td>
		<input type="text" name="tmpt_lahir" size="10" title="Tempat" class="required" /> -
		<select name="tgl" class="required">
<?php
$tglAktif=substr($e['tgl_lahir'],8,2);
for($tt=1;$tt<=31;$tt++){
	if(strlen($tt)==1) $tt="0".$tt; else $tt=$tt;
	if($tt == $tglAktif){
		echo "<option value='$tt' selected>$tt</option>";
	}
	else {
		echo "<option value='$tt'>$tt</option>";
	}
}
?>        			
        </select> -		
		<select name="bulan" class="required">
			<option value="">Bulan</option>
		<?php 
		$blnAktif=substr($e['tgllahir'],5,2);
		$arrBulan=1;
		while($arrBulan<=12){
			if($blnAktif==$arrBulan){
				echo "<option value='$arrBulan' selected>".getBulan($arrBulan)."</option>";
			}
			else {
				echo "<option value='$arrBulan'>".getBulan($arrBulan)."</option>";
			}
			$arrBulan++;
		}
		?>
        </select>-
		<select name="thn" class="required">
	    <option value="">Tahun</option>
		<?php
		for($th=date(Y);$th>=(date(Y)-35);$th--){
			if($e['tahun']==$th){
				echo "<option value='$th' selected>$th</option>";
			}
			else {
				echo "<option value='$th'>$th</option>";
			}
		}
		?>			
		</select><small>Tempat, tgl-bln-thn</small></td>
  </tr>
  <tr>
  <th>Agama</th>
	<td>
	<select name="agama" class="required">	
	<option value="">--Pilih Agama--</option>
    <?php
      // tampilkan agama
      $sql = mysql_query("SELECT * FROM tb_agama");
      while($k=mysql_fetch_array($sql)){
         echo "<option value=$k[id_agama]>$k[agama]</option> \n";
      }
     ?>
      </select>
	</td>
	</tr>
    <tr>
  	<th>Nama Orang Tua</th>
	<td><input type="text" name="nama_ortu" size="50" class="required" /></td>
  </tr>
  <tr>
  	<th>Pekerjaan Orang Tua</th>
	<td><input type="text" name="pekerjaan_ortu" size="50" class="required" /></td>
  </tr>
  <tr>
   	<th valign="middle">Alamat</th>
	<td><textarea name="alamat" style="width:98%; height:50px;" class="required"></textarea></td>
  </tr>
  <tr>
  	<th>No Handphone</th>
	<td><input type="text" name="no_hp" size="15" class="required" /></td>
  </tr>
 <tr>
  	<th>Asal Sekolah</th>
	<td><input type="text" name="asal_sekolah" size="50" class="required" /></td>
  </tr>
  <tr>
  	<th>Niali Matematika</th>
	<td><input type="text" name="matematika" size="5" class="required" /></td>
  </tr>
   
  <tr>
  	<th>Nilai Bhs.Indonesia</th>
	<td><input type="text" name="indonesia" size="5" class="required" /></td>
  </tr>
  <tr>
  	<th>Nilai Bhs.Inggris</th>
	<td><input type="text" name="inggris" size="5" class="required" /></td>
  </tr>
  <tr>
  	<th>Nilai IPA</th>
	<td><input type="text" name="ipa" size="5" class="required" /></td>
  </tr>
  <tr>
  	<th>Keterangan Ijazah</th>
	<td><input type="text" name="ket_ijazah" size="4" class="required" /></td>
  </tr>
  <tr>
  	<th>Username</th>
	<td><input type="text" name="user_id" size="20" class="required" /></td>
  </tr>
  
  <tr>
  	<th>Kode Aman</th>
	<td><img src="captcha.php" /></td>
 </tr>
 <tr>
 	<th>Masukkan Kode</th>
	<td><input type="text" name="kode" size="6" maxlength="6" class="required"/></td>
 </tr>
 <tr>
 	<td colspan="2" align="center">
		<input type="submit" value="Daftar" class="submit" />
	</td>
 </tr>
</table>
</form>
<?php
}
?>
 </div>
 	<div style="clear:both" />
 	<div id="footer" align="center"><?php echo $namasitus; ?> <br><br>&copy; 2014. Copyrigt by: <a href="author.php">Lulu Infajaroh</a>
	<a href="#header" title="Kembali ke Atas"><img src="images/go-top.png" style="float:right; width:15px; height:15px;" /></a></div>
 </div>
 <script type="text/javascript">
$(document).ready(function(){
	$("#form_daftar").validate();
});
</script>
</body>
</html>